//
// Created by hugan on 2021/9/13.
//
#ifndef HTTSCPP_HTTSJNA_CPP
#define HTTSCPP_HTTSJNA_CPP

#include "../sapi/SAPIManager.h"

#ifdef __cplusplus
extern "C" {
#endif
#define EXPORT __declspec(dllexport)

//=====
SAPIManager *sapiManager = nullptr;

/**
 * dll版本号
 */
EXPORT const char *version() {
    return "2021-09-15";
}

/**
 * 初始化
 */
EXPORT HRESULT init(bool logDebug0) {
    if (sapiManager) return 0;
    sapiManager = new SAPIManager();
    HRESULT hr = sapiManager->init(logDebug0);
    if (FAILED(hr)) sapiManager = nullptr;
    return hr;
}

/**
 * 释放所有对象
 */
EXPORT void doFree() {
    if (sapiManager) {
        sapiManager->release();
        sapiManager = nullptr;
    }
}

/**
 * 遍历语音引擎
 */
EXPORT HRESULT enumVoice(func_enumVoiceCallback callback) {
    return sapiManager->enumVoice(callback);
}

/**
 * @param voiceIndex enumVoice中得到的引擎index
 */
EXPORT HRESULT setVoice(int voiceIndex) {
    return sapiManager->setVoice(voiceIndex);
}

/**
 * @param volume 音量[0,100],默认是100
 */
EXPORT HRESULT setVolume(int volume) {
    return sapiManager->setVolume(volume);
}

/**
 * @param rate 播放速度[-10,10],默认是0
 */
EXPORT HRESULT setRate(int rate) {
    return sapiManager->setRate(rate);
}

EXPORT HRESULT speak(const wchar_t *text) {
    //wprintf(L"text=%S\n", text);
    return sapiManager->speak(text);
}

EXPORT HRESULT stop() {
    return sapiManager->stop();
}

EXPORT HRESULT pause() {
    return sapiManager->pause();
}

EXPORT HRESULT resume() {
    return sapiManager->resume();
}

#ifdef __cplusplus
}
#endif
#endif //HTTSCPP_HTTSJNA_CPP